let fs = require('fs');
let fileName = './1.txt';
fs.exists(fileName, function (result) {

    if (result) {
        fs.readFile(fileName, function (err, data) {
            console.log(data.toString());
        })
    }
});

let promise = new Promise(function (resolve, reject) {
    setTimeout(function () {
        resolve('我是成功状态');
    }, 200);

});

function promiseFun() {

    let promise = new Promise(function (resolve, reject) {
        setTimeout(function () {
            resolve('我是成功状态');

        }, 200);

    });
    return promise;
}

async function demo() {
    let result = await promiseFun();
    console.log(result);
    console.log('1');
    console.log('2');
    console.log('3');
}


function readFileByPromise(filename){
    return new Promise(function(resolve,reject){
        fs.readFile(fileName,function(err,data){
            if(err){
                reject(err.message);
            }else{
                resolve(data.toString());
            }
        })
    })
}
async function handleFile(fileName){
    let content = await readFileByPromise(fileName);
    console.log(content);
}

handleFile('./1.txt');